package com.frxuexi.park2212.hourse

import android.annotation.SuppressLint
import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.HourseBeanItem
import com.frxuexi.park2212.R

class HourseAdapter(vm:HourseViewModel):BaseQuickAdapter<HourseBeanItem,BaseViewHolder>(R.layout.item_house) {
    lateinit var vm:HourseViewModel
    init {
        this.vm=vm
    }
    @SuppressLint("ResourceAsColor")
    override fun convert(helper: BaseViewHolder, item: HourseBeanItem) {
        helper.setText(R.id.room,"${item.id}室")
        helper.setText(R.id.qiye,item.enterpriseName)
        helper.setText(R.id.mianji,"${item.area}m²")
        val tv = helper.getView<TextView>(R.id.status)
        if(item.rented){
            tv.setText("已出租")
            tv.setBackgroundResource(R.drawable.shape_solid_red)
            tv.setTextColor(R.color.darkred)
        }else{
            tv.setText("未出租")
            tv.setBackgroundResource(R.drawable.shape_status)
            tv.setTextColor(R.color.green)
        }

        tv.setOnClickListener {
            if(tv.text.toString()=="未出租"){
                vm.rent(item.id,vm.getDate(System.currentTimeMillis()))
//                tv.setText("已出租")
                item.rented=true

            }else{
                vm.unrent(item.id)
                item.rented=false
            }
            notifyDataSetChanged()
        }

    }
}